package com.linln.admin.system.web;

import com.github.pagehelper.Page;
import com.linln.common.utils.HttpServletUtil;
import com.linln.common.utils.ResultVoUtil;
import com.linln.common.vo.ResultVo;
import com.linln.modules.system.entity.BeautyCompany;
import com.linln.modules.system.entity.UserAccountDetail;
import com.linln.modules.system.service.PointsServices;
import com.linln.modules.system.vo.admins.AdminUserPointVo;
import com.linln.modules.system.vo.admins.PointDetailOverBillVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "/mains/points")
public class PointsController extends BaseController {


    @Autowired
    private PointsServices pointsServices;

    @RequestMapping(value = "/index")
    @RequiresPermissions("mains:company:index")
    public ModelAndView getIndex(String nickName,Integer pageNum){
        Integer pageIndex = HttpServletUtil.getParameterInt("size", 1);
        pageNum = pageNum == null ? super.pageNum : pageNum;
        ModelAndView view = new ModelAndView();
        view.setViewName("/mains/points/index");
        Page<AdminUserPointVo> company = pointsServices.getUserPointVoPager(pageNum,pageIndex*10,nickName);
        view.addObject("list",company.getResult());
        view.addObject("page",company);
        view.addObject("nickName",nickName);
        return view;
    }


    @RequestMapping(value = "/detail/{id}",method = RequestMethod.GET)
    public ModelAndView catDetail(@PathVariable("id")String userId, String accountId){
        ModelAndView view = new ModelAndView();
        view.setViewName("/mains/points/detail");
        List<PointDetailOverBillVo> detail = pointsServices.getAllDetail(userId);
        view.addObject("detail",detail);
        return view;
    }

    @ResponseBody
    @RequestMapping(value = "/status/{state}/{id}",method = RequestMethod.GET)
    public ResultVo statusPoints(@PathVariable("id")String id, @PathVariable("state")int s){
        ResultVo vo = ResultVoUtil.error("操作失败");
        try {
            int i = pointsServices.lockAndRelease(id, s);
            if(i>0){
                vo.setCode(200);
                vo.setMsg("操作成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vo;
    }
}
